import axios from 'axios';

var instance = axios.create({
  baseURL: 'http://localhost:8080',
  timeout: 10000,
  headers: {
    'Content-Type': 'application/json',
    'X-PINGOTHER': 'pingpong'
  },
  withCredentials: true
});

const AjaxUtils = {
  get: (url, param) => {
    return instance.get(url, {
      params: param
    }).then(resp => {
      return resp;
    }).catch(function (error) {
      console.log(error);
    });
  },
  post: (url, param) => {
    return instance.post(url, param).then(resp => {
      return resp;
    }).catch(function (error) {
      console.log(error);
    });
  },
  put: (url, param) => {
    return instance.put(url, param).then(resp => {
      return resp;
    }).catch(function (error) {
      console.log(error);
    });
  }
}

export default AjaxUtils;
